function loadDocCategory(){
	var docType = $("#docTypeID").val();
	
	$.getJSON("fetchCategory.htm",{id: $(this).val(), ajax: 'true',parentlevel: docType}, function(j){
		 var options = '';
		 var numOfOptions = j.length;
		 if(numOfOptions > 0){
		      for (var i = 0; i < j.length; i++) {
		        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		      }
		 }else{
			 alert("No Categories mapped to selected document type.");
			 $("#docSubCatID").empty();
		 }
      $("#docCatID").html(options);
      if(numOfOptions > 0){
	      loadDocSubCategory();
      }
    })	;
}

function loadDocSubCategory(){
	var docCat = $("#docCatID").val();
	$.getJSON("fetchSubCategory.htm",{ajax: 'true',parentlevel: docCat}, function(j){
		 var options = '';
		 var numOfOptions = j.length;
		 if(numOfOptions > 0){
			 for (var i = 0; i < j.length; i++) {
				 options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			 }
		 }
      $("#docSubCatID").html(options);
    });	
	
}

//function loadAttributes(docType)
//{
//	var url = $("#uploadNewDocForm").attr("action");
//	var originalTypeId = $("#originalDocTypeId").val();
//	$.post(url,{documentType:docType,originalTypeId:originalTypeId,ajaxSource:"ajaxRequest",_eventId:"loadAttrForDocType"},function(data){
//		$("#dynamicMetaAttr").empty().html(data);
////		addOrEditLayout.resizeAll();
//	},"html");
//}
function bindEventsForDocAttrDtlsPage(){
	$("#docTypeID").change(function(){
		var docType = $("#docTypeID").val();
		loadDocCategory();
//		loadAttributes(docType);
		});
	$("#docCatID").change(function(){
		loadDocSubCategory();
	});
}

function bindEventsForDocDtlsPage(){
	$("#docID").change(function(){
		var docType = $("#docID").val();
		loadDocCategoryForDiv();
		//loadAttributes(docType);
		});
	$("#docCategID").change(function(){
		loadDocSubCategoryForDiv();
	});
	
}

function loadDocCategoryForDiv(){
	var docType = $("#docID").val();
	
	$.getJSON("fetchCategory.htm",{id: $(this).val(), ajax: 'true',parentlevel: docType}, function(j){
		 var options = '<option value="0">ALL</option>';
		 var numOfOptions = j.length;
		 if(numOfOptions > 0){
		      for (var i = 0; i < j.length; i++) {
		        options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
		      }
		 }else{
			 alert("No Categories available for selected document type.");
			 $("#docSubCategID").empty();
		 }
      $("#docCategID").empty().html(options);
      /*if(numOfOptions > 0){
    	  loadDocSubCategoryForDiv();
      }*/
    })	;
}

function loadDocSubCategoryForDiv(){
	var docCat = $("#docCategID").val();
	$.getJSON("fetchSubCategory.htm",{ajax: 'true',parentlevel: docCat}, function(j){
		var options = '<option value="0">ALL</option>';
		 var numOfOptions = j.length;
		 if(numOfOptions > 0){
			 for (var i = 0; i < j.length; i++) {
				 options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
			 }
		 }else{
			 alert("No Sub-Categories available for selected document category.");
		 }
      $("#docSubCategID").empty().html(options);
    });	
	
}

function loadContentToServer(formId,containerId){
	var options ={
			target: "#"+containerId,
			type: 'post',
			data: {},
			success: showResponse,
			iframe: true
	};
	$("#"+formId).ajaxSubmit(options);
	$.blockUI();
}

function showResponse(responseText, statusText, xhr, $form)  
{
	$.unblockUI(); 
/*	$('form').clearForm();*/
/*	alert("Submitted Successfully");*/
}

